﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

namespace CreatePersonTable
{
    class Worker
    {
        static string rootPath = System.IO.Directory.GetCurrentDirectory();
        static string datasetType = "trans";
        static string mcbAggUser = "-N-Predict-AggUser-F.csv";
        static string lclAggUser = "-L-Predict-AggUser-F.csv";

        public static void Setup(string[] args)
        {
            int idx = 0;
            while (idx < args.Length && args[idx].StartsWith("-"))
            {
                string p = args[idx].ToLower().Substring(1);
                if (p == "datatype")
                    datasetType = args[++idx];                
            }
        }

        public static void ReadTable()
        {
            string localAggUserFile = rootPath + "\\" + datasetType + lclAggUser;
            string nAggUserFile = rootPath + "\\" + datasetType + mcbAggUser;

            StreamReader lReader = new StreamReader(localAggUserFile);
            StreamReader nReader = new StreamReader(nAggUserFile);
            StreamWriter writer = new StreamWriter(rootPath + "\\A-" + datasetType + "-Table.csv");

            string line;
            Dictionary<string, double> lAccuracy = new Dictionary<string, double>(), nAccuracy = new Dictionary<string, double>();
            while ((line = lReader.ReadLine()) != null)
            {
                string[] splits = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (splits.Length != 2)
                    continue;
                lAccuracy.Add(splits[0],double.Parse(splits[1]));
            }
            while ((line = nReader.ReadLine()) != null)
            {
                string[] splits = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (splits.Length != 2)
                    continue;
                nAccuracy.Add(splits[0], double.Parse(splits[1]));
            }

            if (lAccuracy.Count != nAccuracy.Count)
                writer.WriteLine("Length Not Compatible");
            else
            {
                foreach (string name in lAccuracy.Keys)
                {
                    writer.WriteLine(name + ",0," + lAccuracy[name].ToString("0.0000") + "," + nAccuracy[name].ToString("0.0000"));
                }
            }
            writer.Close();
            lReader.Close();
            nReader.Close();
        }
    }
}
